<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>后台登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
 <script src="./jqueryqrcode/src/jquery.min.js"></script>
 <script src="./jqueryqrcode/src/qrcode.js"></script>
 <script src="./jqueryqrcode/src/jquery.qrcode.js"></script>
 </head>
  
  <style type="text/css">
  body {
  	background-image: url(./img/bamQrLogin.jpg);
  	background-repeat:no-repeat;
  	background-position:center;
  	background-size:100%;
  }
  #divCon{
  	height: 320px;
  	width:350px;
  	background-color: white;
  }
  #div{
  	margin: 10% auto;
  	height: 430px;
  	width:350px;
  	background-color: white;
  }
  #qrcode{
 	 margin-left:  45px;
  }
  #p{
 	padding-left: 45px;
  	font-size: 14px;
  	color: #708090;
  }
  #head{
  	font-weight:800;
  	color:#ffa500;
  	style=font-size:26px; 
  	padding-top:15px; 
  	padding-left: 45px;
  }
  #time{
  padding-left: 45px;
  	font-size: 14px;
  	color: #708090;
  }
  </style>
  </head>
  
 <body onload="yanzheng()">
 	<div id="div">
    	<p id="head">牛郎网络</p>
   			<div id="qrcode"></div>
        <br>
       
        <p id="p">使用牛郎wifi-APP扫描登录管理后台界面
        <p><font id="time"></>
        
    </div>
    
    <form action="${pageContext.request.contextPath}/GuanLogin/admin_adminLogin.action" method="post">
    	<input name="userPhone" type="hidden" id="userPhone" >
    	<input name="pwd" type="hidden" id="pwd" >
    </form>
</body>
<script>
	function yanzheng (){
			var a = "${requestScope.No}";
			if(a!=""){
				alert(a);
			}
			if (window.top!=window.self){
				window.top.location="${pageContext.request.contextPath}/jsp/QRlogin.jsp";
			}
		}
    $(document).ready(function() {
        var uuid;
    
         $.ajax({
		   type: "get",
		   url: "${pageContext.request.contextPath}/GuanLogin/admin_QRcodeLogin.action",
		   data: {},
		   dataType:"json",
		   success: function(msg){
		    var obj = eval("("+msg+")");
		     //存储UUID
            uuid = obj.uuid;
            var text = obj.text;
            var jsonStr = JSON.stringify( text );
           
            //显示二维码
            jQuery('#qrcode').qrcode({
				text	: jsonStr
			});
			init()	;
            //开始验证登录
        	validateLogin();
		    },
		     	error:function(){
		   		alert("系统出错误,请联系技术人员");
		   }
		    });
 			var j=0;
        function validateLogin(){
       		 var timestamp1=new Date().getTime();//每次请求前时间
           $.ajax({
		   type: "get",
		   url: "${pageContext.request.contextPath}/GuanLogin/admin_checkLogin.action?sessionId="+uuid,
		   data: {},
		   dataType:"json",
		   success: function(msg){
		   		var timestamp2=new Date().getTime();//每次请求成功后时间
		   		var timestamp = timestamp2-timestamp1;
                if(msg == ""){
                	j=j+timestamp;
                	if(j<300000){//5分钟后不再请求后台
                    	validateLogin();
                    }
                }else{
                 	var obj = eval("("+msg+")");
                	var userPhone = obj.userPhone;
                	var pwd = obj.pwd;
                	$("#userPhone").val(userPhone);
                	$("#pwd").val(pwd);
                	$("form:first").submit();
                }
            }});
         }
    });
    
    function init(){
		var t;
		shownum();
		}
	var i =300; 
	function shownum(){ 
	i=i-1; 
	if(i>-1){
		document.getElementById("time").innerHTML="二维码在 "+i+"s 后失效 !";
		t = setTimeout('shownum()',1000); 
	}else{
		document.getElementById("time").innerHTML="二维码已失效,请  "+"<a href='${pageContext.request.contextPath}/jsp/QRlogin.jsp'>刷新</a>";
		clearTimeout(t);
		}
	}
</script>
</html>
